package com.smm.web.vmc.service.impl;

import com.smm.web.vmc.dao.BaseDao;
import com.smm.web.vmc.domain.AppInfo;
import com.smm.web.vmc.service.AppInfoService;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by zhenghao on 2016/10/14.
 *
 */
@Service
public class AppInfoServiceImpl implements AppInfoService {

    @Resource
    private BaseDao<AppInfo> appInfoBaseDao;

    @Override
    public AppInfo getLastInfo() {

        DetachedCriteria where = DetachedCriteria.forClass(AppInfo.class);
        where.addOrder(Order.desc("id"));

        List<AppInfo> appInfos = (List<AppInfo>) this.appInfoBaseDao.getTemplate().findByCriteria(where,0,1);

        if(appInfos!=null && appInfos.size()>0) return appInfos.get(0);

        return null;

    }
}
